package com.arox.springinaction.sequence;

import java.util.List;
import java.util.Map;
import java.util.Properties;

public class SequenceGenerator {

    private String prefix;
    private String suffix;
    private int initial;
    private int counter;
    private List<Object> suffixes;
    private Map<Object, Object> mapSuffixes;
    private Properties propSuffixes;

    public SequenceGenerator() {
    }

    public SequenceGenerator(String prefix, String suffix, int initial) {
	this.prefix = prefix;
	this.suffix = suffix;
	this.initial = initial;
    }

    public synchronized String getSequence() {
	StringBuffer buffer = new StringBuffer();
	buffer.append(prefix);
	buffer.append(initial + counter++);
	buffer.append(suffix);
	for (Object suffix : suffixes) {
	    buffer.append("-");
	    buffer.append(suffix);
	}
	for (Map.Entry entry : mapSuffixes.entrySet()) {
	    buffer.append("-");
	    buffer.append(entry.getKey());
	    buffer.append("@");
	    buffer.append(entry.getValue());
	}
	for (Map.Entry entry : propSuffixes.entrySet()) {
	    buffer.append("-");
	    buffer.append(entry.getKey());
	    buffer.append("@");
	    buffer.append(entry.getValue());
	}
	return buffer.toString();
    }
    
    public Properties getPropSuffixes() {
        return propSuffixes;
    }

    public void setPropSuffixes(Properties propSuffixes) {
        this.propSuffixes = propSuffixes;
    }

    public Map<Object, Object> getMapSuffixes() {
        return mapSuffixes;
    }

    public void setMapSuffixes(Map<Object, Object> mapSuffixes) {
        this.mapSuffixes = mapSuffixes;
    }

    public List<Object> getSuffixes() {
	return suffixes;
    }

    public void setSuffixes(List<Object> suffixes) {
	this.suffixes = suffixes;
    }

    public String getPrefix() {
	return prefix;
    }

    public void setPrefix(String prefix) {
	this.prefix = prefix;
    }

    public String getSuffix() {
	return suffix;
    }

    public void setSuffix(String suffix) {
	this.suffix = suffix;
    }

    public int getInitial() {
	return initial;
    }

    public void setInitial(int initial) {
	this.initial = initial;
    }

    public int getCounter() {
	return counter;
    }

    public void setCounter(int counter) {
	this.counter = counter;
    }

}
